package com.itheima.controller;

import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result pageQuery(StudentQueryParam studentQueryParam) {
        PageResult pageResult = studentService.pageQuery(studentQueryParam);
        return Result.success(pageResult);
    }

   @DeleteMapping("/{id}")
   public Result delete(@PathVariable  List<Integer> id) {
        log.info("ids{}",id);
       studentService.deleteByIds(id);
       return Result.success();
   }

   @PostMapping
    public Result add(@RequestBody Student student) {
        log.info("添加学员，参数：{}", student);
        studentService.add(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Student student = studentService.getById(id);
        return Result.success(student);
    }

    @PutMapping
    public Result update(@RequestBody Student student) {
        log.info("更新学员信息，参数：{}", student);
        studentService.update(student);
        return Result.success();
    }


    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id,@PathVariable Integer score){
        studentService.violation(id,score);
        return Result.success();
    }

}
